#include <iostream>
#include <sstream>

#include "Scanner.h"
#include "Parser.h"
#include "TypeVisitor.h"
#include "Module.h"

int main()
{
	using namespace moses;
	
	std::stringstream module(
		"hej :: Int, Int\n"
		": hej 0 = 100\n"
		": hej 1 = 2 * hej(0)\n"
		": hej 2 = 2 * hej(1)\n"
		"\n"
		"main :: Int, Int\n"
		": main _ = hej (2) + hej (1)\n"
	
	);
	
	Scanner scanner(module);
	Parser parser(scanner);

	std::stringstream errors;	
	TypeVisitor typeChecker(errors);	
	Module *pModule = (Module*)parser.BuildTree();
	
	typeChecker.Accept(pModule);
	
	Runtime env(pModule);	
	
	if (typeChecker.NumErrors() == 0)
		std::cout << pModule->Bootstrap(&env, "main", "").ToString() << std::endl;
	else
		std::cout << errors.str() << std::endl << typeChecker.NumErrors() << " error(s)." << std::endl;
	
	
	return 0;
}